
#include <iostream>
#include <stdio.h>

#include<string.h>
#include<ctype.h>

#include <math.h>
#include<time.h>

using namespace std;

#define maxn 100
char arr[maxn];

// temp
#define lenPuzzle 11
char arrPuzzle[lenPuzzle][lenPuzzle];
int arrPuzzleNumber[lenPuzzle][lenPuzzle];
// 0: char
// 1: number

int main() {

    // redirect in outw
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif // TEST

    int i, j, k; // loop
    int temp, len, count=0, numberResult=0; // temp, count
    int a,b, t; // cin

    // result
    bool isFirstLine= true;
    bool isFirstSpace= true;
    double result=0;
    int r1, r2,r3;

    // temp
    int lenX, lenY, nEligible=0;
    int x,y, preX, preY;


//    memset(arr, 0, sizeof(arr));

//    cin >> t;
//    while (t-- > 0)
//    scanf("%s", arr);

//gets(arr) != NULL && strcmp(arr,"Z") != 0

    while(scanf("%d", &lenX) != EOF && lenX) {
        // init
        //lenX = arr[0] - '0', lenY = arr[2] - '0';
        scanf("%d", &lenY);
        for (i = 0; i < lenPuzzle; i++) {
            arrPuzzle[0][i] = '*';
            arrPuzzle[i][0] = '*';
        }
        nEligible = 0;
        memset(arrPuzzleNumber, 0, sizeof(arrPuzzleNumber));

        // in
//        scanf("%d", &aaa);
//        scanf("%s", arr);

        for (i = 1; i <= lenX; i++) {
            scanf("%s",arr);
            for (j = 1; j <= lenY; j++) {
                arrPuzzle[i][j] = arr[j-1];
            }
        }

        // start
        for (i = 1; i <= lenX; i++) {
            for (j = 1; j <= lenY; j++) {
                if (arrPuzzle[i][j] != '*' &&
                    ((i-1 >=0 && arrPuzzle[i-1][j]=='*') ||
                    (j-1 >=0 && arrPuzzle[i][j-1]=='*'))) {
                        arrPuzzleNumber[i][j] = ++nEligible;
                }
            }
        }

        // output format

        if (isFirstLine) isFirstLine = false;
        else cout<< endl;

        cout << "puzzle #" <<++numberResult<<":"<<endl;

        bool isFirstAD = true;
        cout << "Across" << endl;
        for (i=1; i<=lenX; i++) {
            for (j=0; j<=lenY; j++) {
                if (arrPuzzle[i][j] == '*' &&
                    j+1 <=lenY&&
                    arrPuzzle[i][j+1]!='*') {

                    isFirstAD = true;
                    //
                    for (k=j+1; k <=lenY; k++ ) {
                        if (arrPuzzle[i][k]!='*') {
                            if (isFirstAD) {
                                isFirstAD = false;
                                printf("%3d.", arrPuzzleNumber[i][k]);
                            }

                            cout<< arrPuzzle[i][k];
                        } else {
                            break;
                        }
                    }
                    //
                    j=k-1;
                    cout << endl;
                }
            }
        }

        cout << "Down" << endl;
        for (i=0; i<=lenX; i++) {
            for (j=1; j<=lenY; j++) {
                if (arrPuzzle[i][j] == '*' &&
                    i+1 <=lenX&&
                    arrPuzzle[i+1][j]!='*') {

                    isFirstAD = true;
                    //
                    for (k=i+1; k <=lenX; k++ ) {
                        if (arrPuzzle[k][j]!='*') {
                            if (isFirstAD) {
                                isFirstAD = false;
                                printf("%3d.", arrPuzzleNumber[k][j]);
                            }

                            cout<< arrPuzzle[k][j];
                        } else {
                            break;
                        }
                    }
                    //
                    cout << endl;
                }
            }
        }

    }


//    scanf("%d%d", &lenX, &lenY);

    return 0;
}


